﻿using System;
using System.Collections.Generic;

namespace ProjectEuler
{
    public struct Tuple<T1, T2> : IEquatable<Tuple<T1, T2>>
    {
        public readonly T1 A;
        public readonly T2 B;

        public Tuple(T1 a, T2 b)
        {
            this.A = a;
            this.B = b;
        }

        public override Int32 GetHashCode()
        {
            return
                EqA.GetHashCode(A) ^
                EqB.GetHashCode(B);
        }

        public override Boolean Equals(Object obj)
        {
            if (obj is Tuple<T1, T2>)
            {
                return Equals((Tuple<T1, T2>)(obj));
            }

            return false;
        }

        public Boolean Equals(Tuple<T1, T2> other)
        {
            return
                EqA.Equals(A, other.A) &&
                EqB.Equals(B, other.B);
        }

        private static IEqualityComparer<T1> EqA { get { return EqualityComparer<T1>.Default; } }
        private static IEqualityComparer<T2> EqB { get { return EqualityComparer<T2>.Default; } }
    }
}
